﻿using System;
using System.Collections;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using System.Globalization;
using KPIS.GERP.GAMS.APP.Reports;
using KPIS.GERP.GAMS.DAL;
using KPIS.GERP.GAMS.MODEL;
using System.Collections.Generic;
using Telerik.Web.UI;
using System.Web.UI;

namespace KPIS.GERP.GAMS.APP.App_UI.Forms
{
    public partial class ACM_VIEW_Reports : System.Web.UI.Page
    {
        Commons.Main main = new Commons.Main();
        D_ACM_MAS_Account d_acm_mas_account = new D_ACM_MAS_Account();
        D_ACM_ACC_CHANGE_Value d_acm_change_value = new D_ACM_ACC_CHANGE_Value();
        D_ACM_MAS_FISCAL_Period d_acm_fiscal_period = new D_ACM_MAS_FISCAL_Period();
        D_ACM_BOOK_Bank d_acm_book_bank = new D_ACM_BOOK_Bank();
        D_ACM_Finance_Receive d_acm_finance_receive = new D_ACM_Finance_Receive();
        D_ACM_INVENTORY_Control d_acm_inventory_control = new D_ACM_INVENTORY_Control();
        string strReportName;
        protected void CrystalReportViewer1_Init(object sender, EventArgs e)
        {
            strReportName = Request.QueryString["ReportName"];
            LoadReport(strReportName);
        }
        private void LoadReport(string ReportName)
        {
            switch (ReportName)
            {
                case "R_ACM_BOOK_Bank":
                    Page.Title = "รายงานสมุดเงินฝากธนาคาร";
                    R_ACM_BOOK_Bank reportBookBank = new R_ACM_BOOK_Bank();
                    reportBookBank.Refresh();
                    reportBookBank.SetDataSource(d_acm_book_bank.Report_BOOK_Bank());
                    reportBookBank.SetParameterValue("CreateBy", main.strEmpID);
                    reportBookBank.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "MappingBookBank");
                    //CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                    //CrystalReportViewer1.ReportSource = reportBookBank;
                    //CrystalReportViewer1.DataBind();
                    break;
                case "R_ACM_FINANCE_Receive":
                    Page.Title = "รายงานจำแนกพัสดุ";
                    R_ACM_FINANCE_Receive reportFinReceive = new R_ACM_FINANCE_Receive();
                    reportFinReceive.Refresh();
                    reportFinReceive.SetDataSource(d_acm_finance_receive.Report_FINANCE_Receive());
                    reportFinReceive.SetParameterValue("CreateBy", main.strEmpID);
                    CrystalReportViewer1.ReportSource = reportFinReceive;
                    CrystalReportViewer1.DataBind();
                    break;
                case "R_ACM_ACCOUNT_Code":
                    Page.Title = "รายงานแสดงรหัสบัญชี";
                    R_ACM_ACCOUNT_Code reportAccount = new R_ACM_ACCOUNT_Code();
                    reportAccount.SetDataSource(d_acm_mas_account.Report_ACCOUNT_Code());
                    reportAccount.SetDatabaseLogon(main.strUserName, main.strPassword, main.strServerName, main.strDatabaseName);
                    reportAccount.SetParameterValue("CreateBy", main.strEmpID);
                    reportAccount.ExportToHttpResponse(ExportFormatType.Excel, Response, true, "Account");
                    //CrystalReportViewer1.ReportSource = reportAccount;
                    //CrystalReportViewer1.DataBind();
                    break;
                case "R_ACM_CHANGE_Value":
                    Page.Title = "รายงานปรับค่าต่าง ๆ ของทางบัญชี";
                    R_ACM_CHANGE_Value reportChangeValue = new R_ACM_CHANGE_Value();
                    reportChangeValue.SetDataSource(d_acm_change_value.Report_ACCOUNT_CHANGE_Value());
                    reportChangeValue.SetDatabaseLogon(main.strUserName, main.strPassword, main.strServerName, main.strDatabaseName);
                    reportChangeValue.SetParameterValue("CreateBy", main.strEmpID);
                    CrystalReportViewer1.ReportSource = reportChangeValue;
                    CrystalReportViewer1.DataBind();
                    break;
                case "R_ACM_FISCAL_Period":
                    Page.Title = "รายงานแสดงงวดบัญชี";
                    R_ACM_FISCAL_Period reportFiscalPeriod = new R_ACM_FISCAL_Period();
                    reportFiscalPeriod.SetDataSource(d_acm_fiscal_period.Report_FISCAL_Period());
                    reportFiscalPeriod.SetDatabaseLogon(main.strUserName, main.strPassword, main.strServerName, main.strDatabaseName);
                    reportFiscalPeriod.SetParameterValue("CreateBy", main.strEmpID);
                    CrystalReportViewer1.ReportSource = reportFiscalPeriod;
                    CrystalReportViewer1.DataBind();
                    break;
            }
            CrystalReportViewer1.DataBind();
        }
        public void Page_Load(object sender, EventArgs e)
        {
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
        }
    }
}
